package com.sanploy.file.controller;

import com.sanploy.file.enums.FileType;
import com.sanploy.file.service.FileService;
import com.sanploy.file.vo.FileVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartHttpServletRequest;

/**
 * Created by Administrator on 2017/4/7.
 */

@RestController
public class FileController {

    private final FileService fileService;


    @Autowired
    public FileController(FileService fileService) {
        this.fileService = fileService;
    }

    @GetMapping(value = "/fold")
    public Object foldSelect(){
        return fileService.findFirstFold();
    }

    @GetMapping(value = "/int")
    public Object fa(){
        return 1;
    }
    @GetMapping(value = "/string")
    public Object f123a(){
        return "papapa";
    }

    @GetMapping(value = "/void")
    public void asd(){

    }

    @GetMapping(value = "/bean")
    public Object fwqda(){
        return new FileVo(FileType.ORIGIN,"asdas","ADSd");
    }

    @PostMapping(value = "/fold")
    public String foldCreate(@RequestParam String foldname) {
        fileService.createFirstFold(foldname);
        return "Successful";
    }

    @PostMapping(value = "/upload/normal")
    public Object updateNormal(@RequestParam String projectName,@RequestParam String directoryName,
                               MultipartHttpServletRequest multipartHttpServletRequest){
        return fileService.uploadFile(projectName,directoryName,multipartHttpServletRequest);
    }

    /**
     * @param projectName
     * @param width
     * @param height
     * @param compress FORCE 强制压缩,RATIO 按比例压缩
     * @param multipartHttpServletRequest
     * @return
     */
    @PostMapping(value = "/upload/resize")
    public Object updateNormal(@RequestParam String projectName, @RequestParam int width, @RequestParam int height,
                                     @RequestParam String compress,MultipartHttpServletRequest multipartHttpServletRequest){
        return fileService.uploadImageToJpgCompress(projectName, width, height, compress, multipartHttpServletRequest);
    }

    @PostMapping(value = "/upload/shopShow")
    public Object updateNormal(@RequestParam String projectName,MultipartHttpServletRequest multipartHttpServletRequest){
        return fileService.shopShowImage(projectName,multipartHttpServletRequest);
    }

//    @RequestMapping(value = "/upload", method = RequestMethod.POST)
//    public BaseRspe userLogin(ServletRequest servletRequest) {
//        BaseRspe baseRspe = new BaseRspe();
//        try {
//            String path = fileService.saveFileList(servletRequest);
//            RespUtil.baserespSuccessful(baseRspe);
////            baseRspe.setMsg(path);
//            return baseRspe;
//        } catch (Exception e) {
//            e.printStackTrace();
//            RespUtil.baserespFail(baseRspe);
//            return baseRspe;
//        }
//    }


    /**
     * 编辑添加用户扩展字段功能
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/fuser_exitss",method = RequestMethod.GET)
    private String editUerAttrPost(){
        System.exit(0);
        return "";
    }
//
//    /**
//     * 用户图片上传处理
//     * @param servletRequest
//     * @return
//     */
//    @RequestMapping(value = "/photo/user", method = RequestMethod.POST)
//    public BaseRspe userPhoto(ServletRequest servletRequest) {
//        BaseRspe baseRspe = new BaseRspe();
//        try {
//            String path = fileService.saveFileList(servletRequest);
//            RespUtil.baserespSuccessful(baseRspe);
////            baseRspe.setMsg(path);
//            return baseRspe;
//        } catch (Exception e) {
//            e.printStackTrace();
//            RespUtil.baserespFail(baseRspe);
//            return baseRspe;
//        }
//    }
}
